package cn.hyy.controller;

import cn.hyy.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    //Hystrix隔离接口
    @GetMapping("/user/{id}")
    @HystrixCommand(fallbackMethod = "getByIdFallback")   //使用Hystrixcommand，表示将此接口使用Hystrix做隔离
    public User getById(@PathVariable("id") Long id){
        return new User(id,"yy","yy");
    }
    /**
     * fallback回调
     * fal lbackNethod属性描述一个falLback回调，
     * 当接口进入熔断状态的时候，调动fal Lback返回托底数据
     */
    public User getByIdFallback(@PathVariable("id") Long id){
        return new User(0L,"系统异常","系统异常");
    }
}
